package xiaye.crawler.core.impl;

import it.unimi.dsi.parser.BulletParser;
import it.unimi.dsi.parser.callback.LinkExtractor;

import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import xiaye.crawler.core.LinkParser;

public class BulletLinkParser implements LinkParser {
	List<URI> results = new LinkedList<URI>();
	
	@Override
	public void parse(URI self, String content) {
		BulletParser parser = new BulletParser();
		LinkExtractor callback = new LinkExtractor(); 
		parser.setCallback(callback);
		parser.parse(content.toCharArray());
		Set<String> relatives = callback.urls;
		for (String url : relatives){
			results.add(self.resolve(url));
		}
	}

	@Override
	public List<URI> getOutlinks() {
		return results;
	}

}
